﻿using System;
using System.Web;
using System.Web.Mvc;

namespace Kwd.Summary.Extensions
{
  public static class HtmlExtensions
  {
    /// <summary>
    /// Generate text, using simple predicate.
    /// </summary>
    public static HtmlString If(this HtmlHelper htmlHelper, Func<bool> value, string trueText, string falseText)
    {
      return new HtmlString(value() ? trueText : falseText);
    }

    #region conveniance overloads
    public static HtmlString If(this HtmlHelper htmlHelper, Func<bool> value, string text)
    {
      return If(htmlHelper, value, text, String.Empty);
    }

    public static HtmlString If(this HtmlHelper htmlHelper, bool value, string text)
    {
      return If(htmlHelper, () => value, text, String.Empty);
    }

    public static HtmlString If(this HtmlHelper htmlHelper, bool value, string trueText, string falseText)
    {
      return If(htmlHelper, () => value, trueText, falseText);
    }
    #endregion
  }
}